package com.vitogiovanni.tobook.utilities;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;

public class DatePickerFragment extends DialogFragment {
	OnDateSetListener ondateSet;

	public DatePickerFragment() {
	}

	public void setCallBack(OnDateSetListener ondate) {
		ondateSet = ondate;
	}

	private int year, month, day;

	@Override
	public void setArguments(Bundle args) {
		super.setArguments(args);
		year = args.getInt("year");
		month = args.getInt("month");
		day = args.getInt("day");
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		
		DatePickerDialog dateDialog = new DatePickerDialog(getActivity(), ondateSet, year, month, day);
		dateDialog.setTitle("Selezionare la data");
		DatePicker datePicker = dateDialog.getDatePicker();
		datePicker.setMinDate(System.currentTimeMillis() - 1000);
		
		return dateDialog;
	}
}
